/*
*************************************
* PocketGTT
*************************************
This file is part of PocketGTT.

PocketGTT is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

PocketGTT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with PocketGTT.  If not, see <http://www.gnu.org/licenses/>.
*/

import QtQuick 1.0
//import myGTT 1.0


Item {
    id: msgBanner

//    property int mbStatus: /*myWin.statesMan.mgsBannerStatus*/
    //    property real changetime: 200
    property alias text: msgText.text

    // define size and position
    width: parent.width * 0.8
    height: contentView.height + 50 // 250

    anchors.centerIn: parent

    // visibility
    opacity: 0

    Rectangle {
        id: msgBannerBg
        color: "grey"
        anchors.fill: parent
        radius: 35
        //        opacity: 0.9
    }

    Column
    {
        id: contentView
        anchors.centerIn: parent
        spacing: 10
        width: parent.width

        AnimatedImage {
            id: imgAnim
            source: "qrc:ajax-loader.gif"
            anchors.horizontalCenter: parent.horizontalCenter
        }
        Image {
            id: imgStatic
            source: ""
            anchors.horizontalCenter: parent.horizontalCenter
        }
        Text {
            id: msgText
            text: qsTr("start")
            color: "white"
            anchors.horizontalCenter: parent.horizontalCenter

            horizontalAlignment: Text.AlignHCenter
            font.pixelSize: myWin.theme.textSizeS
            width: parent.width * 0.8
            wrapMode: Text.Wrap

        }

    }


        MouseArea {
            anchors.fill: parent
            onClicked: {
                if(myWin.statesMan.mgsBannerStatus == 2) {//GTTStopInfo.mgsNoPassagesIn2h
                    GTT.MgsBannerStatus = 0; //GTTStopInfo.mgsHidden
                }
                if(myWin.statesMan.mgsBannerStatus == 3) {//GTTStopInfo.errorNonExistingStop
                    GTT.MgsBannerStatus = 0;
                }
                if(myWin.statesMan.mgsBannerStatus == 4) {//GTTStopInfo.errorUnkownResponse
                    GTT.MgsBannerStatus = 0; //GTTStopInfo.mgsHidden
                }
                if(myWin.statesMan.mgsBannerStatus == 5) {//GTTStopInfo.errorDownloadingPage
                    GTT.MgsBannerStatus = 0; //GTTStopInfo.mgsHidden
                }
            }
        }
    states: [
        State {
            name: "hidden"
            when: myWin.statesMan.mgsBannerStatus == 0 //GTTStopInfo.mgsHidden
            PropertyChanges { target: msgBanner; opacity: 0}
            PropertyChanges { target: msgBannerBg; color: "white"}
            PropertyChanges { target: msgText; text: qsTr("")}
            PropertyChanges { target: imgAnim; visible: false}
            PropertyChanges { target: imgStatic; visible: true}
            PropertyChanges { target: imgStatic; source: ""}
        },
        State {
            name: "loading"
            when: myWin.statesMan.mgsBannerStatus == 1 //GTTStopInfo.msgLoading
            PropertyChanges { target: msgBanner; opacity: 1}
            PropertyChanges { target: msgBannerBg; color: myWin.theme.mbLoading}
            PropertyChanges { target: msgText; text: qsTr("Loading")}
            PropertyChanges { target: imgAnim; visible: true}
            PropertyChanges { target: imgStatic; visible: false}
            PropertyChanges { target: imgStatic; source: ""}
        },
        State {
            name: "noPassages"
            when: myWin.statesMan.mgsBannerStatus == 2 //GTTStopInfo.mgsNoPassagesIn2h
            PropertyChanges { target: msgBanner; opacity: 1}
            PropertyChanges { target: msgBannerBg; color:  myWin.theme.mbInfo}
            PropertyChanges { target: msgText; text: qsTr("Nessun passaggio previsto\nnelle prossime 2h")}
            PropertyChanges { target: imgAnim; visible: false}
            PropertyChanges { target: imgStatic; visible: true}
            PropertyChanges { target: imgStatic; source: "qrc:ui/information_userguide.svg"}
        },
        State {
            name: "errorNonExistingStop"
            when: myWin.statesMan.mgsBannerStatus == 3 //GTTStopInfo.errorNonExistingStop
            PropertyChanges { target: msgBanner; opacity: 1}
            PropertyChanges { target: msgBannerBg; color:  myWin.theme.mbError}
            PropertyChanges { target: msgText; text: qsTr("Errore: richiesta fermata inesistente")}
            PropertyChanges { target: imgAnim; visible: false}
            PropertyChanges { target: imgStatic; visible: true}
            PropertyChanges { target: imgStatic; source: "qrc:ui/error.svg"}
        },
        State {
            name: "errorUnkownResponse"
            when: myWin.statesMan.mgsBannerStatus == 4 //GTTStopInfo.errorUnkownResponse
            PropertyChanges { target: msgBanner; opacity: 1}
            PropertyChanges { target: msgBannerBg; color:  myWin.theme.mbError}
            PropertyChanges { target: msgText; text: qsTr("Errore: impossibile decodificare la risposta del server")}
            PropertyChanges { target: imgAnim; visible: false}
            PropertyChanges { target: imgStatic; visible: true}
            PropertyChanges { target: imgStatic; source: "qrc:ui/error.svg"}
        },
        State {
            name: "errorDownloadingPage"
            when: myWin.statesMan.mgsBannerStatus == 5 //GTTStopInfo.errorDownloadingPage
            PropertyChanges { target: msgBanner; opacity: 1}
            PropertyChanges { target: msgBannerBg; color:  myWin.theme.mbError}
            PropertyChanges { target: msgText; text: qsTr("Errore: download della pagina non riuscito")}
            PropertyChanges { target: imgAnim; visible: false}
            PropertyChanges { target: imgStatic; visible: true}
            PropertyChanges { target: imgStatic; source: "qrc:ui/error.svg"}
        }
    ]

}
